<!--tenderRecordStatistics编辑弹窗-->
<template>
    <div class="mycontainer">
        <el-form :label-position="labelPosition" ref="form" :model="form" :rules="rules">
            <el-row>
                <el-col span="9">
                <el-form-item label="备案编号：">
                    <el-input v-model="form.recordNumber" placeholder="请输入内容" ></el-input>
                </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="合同签约日期：">
                    <el-input v-model="form.contractGetDate" :disabled="true"></el-input>
                </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="9">
                <el-form-item label="项目编号：">
                    <el-input v-model="form.projectId" :disabled="true"></el-input>
                </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                     <el-form-item label="项目名称：">
                    <el-input v-model="form.projectName" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            
            <el-row>
                <el-col span="9">
                    <el-form-item label="业主名称：">
                        <el-input v-model="form.customName" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="项目经理：">
                        <el-input v-model="form.projectManager" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col span="9">
                     <el-form-item label="资金来源:">
                        <el-input v-model="form.fundSource" placeholder="请输入内容"></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="项目区域：">
                        <el-input v-model="form.projectArea" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col span="9">
                    <el-form-item label="业主联系人：">
                        <el-input placeholder="请输入内容" v-model="form.ownerContact" type="text" maxlength="10" show-word-limit></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="业主联系电话:" prop="ownerPhone">
                        <el-input placeholder="请输入内容" v-model="form.ownerPhone" oninput ="value=value.replace(/[^\d]/g,'')" show-word-limit></el-input>
                    </el-form-item>
                </el-col>
             </el-row>
            <el-row>
                <el-col span="9">
                    <el-form-item label="招标类型：">
                        <el-input v-model="form.tenderType" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="招标文件发售起止时间:">
                    <el-date-picker v-model="form.startAndEndTime" range-separator="——" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" unlink-panels
                    format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width:100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="9">
                    <el-form-item label="开标时间：">
                        <el-date-picker v-model="form.tenderTime" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd hh:mm:ss" style="width:100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="开标地点:">
                        <el-input placeholder="请输入内容" v-model="form.tenderStartArea" type="text" maxlength="30" show-word-limit></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="9">
                    <el-form-item label="中标人:">
                        <el-input placeholder="请输入内容" v-model="form.tenderWinner" type="text" maxlength="10" show-word-limit></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="9" :offset="6">
                    <el-form-item label="备案时间:">
                        <el-date-picker v-model="form.recordTime" type="date" placeholder="选择日期" format="yyyy-MM-dd " value-format="yyyy-MM-dd hh:mm:ss"  style="width:100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="9">
                    <el-form-item label="备案状态:">
                        <el-input v-model="form.recordState" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span style="text-align:center;display:block;">
              <el-button @click="offSubmit" style="margin-right:20px;">取消</el-button>
              <el-button type="primary" @click="onSubmit">确定</el-button>
        </span>
    </div>
</template>
 
<script>
import { InvitationStatisticsTable } from '@/api/bigdata.js';
export default {
  components: {},
  data () {
    return {
      labelPosition: 'top',
      form: {
        recordNumber: '',
        recordState: '',
        projectId: '',
        projectName: '',
        customName: '',
        ownerContact: '',
        ownerPhone: '',
        contractAmount: '',
        contractGetDate: '',
        tenderType: '',
        projectManager: '',
        projectArea: '',
        tenderPrice: '',
        fundSource: '',
        startAndEndTime: [], // ["2022-03-23","2022-03-25"]
        tenderTime: '',
        tenderStartArea: '',
        tenderWinner: '',
        recordTime: ''
      },
      rules: {
        ownerPhone: [{pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: '请输入正确的电话号码', trigger: 'blur' }]
      }
      // 这个只能验证手机号
      // { pattern:/^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/, message: "请输入合法手机号", trigger: "blur" }
    }
  },
  methods: {
    dataInit (data) {
      if (data) {
        // this.form = data;
        console.info(data);
        this.form.recordNumber = data.recordNumber;
        this.form.recordState = data.recordState;
        this.form.projectId = data.projectId;
        this.form.projectName = data.projectName;
        this.form.customName = data.customName;
        this.form.ownerContact = data.ownerContact;
        this.form.ownerPhone = data.ownerPhone;
        this.form.contractAmount = data.contractAmount;
        this.form.contractGetDate = data.contractGetDate;
        this.form.tenderType = data.tenderType;
        this.form.projectManager = data.projectManager;
        this.form.projectArea = data.projectArea;
        this.form.tenderPrice = data.tenderPrice;
        this.form.fundSource = data.fundSource;
        this.form.tenderTime = data.tenderTime;
        this.form.tenderStartArea = data.tenderStartArea;
        this.form.tenderWinner = data.tenderWinner;
        this.form.recordTime = data.recordTime;
        this.form.startAndEndTime = data.startAndEndTime.split('至');
        console.info(this.form);
      }
    },
    offSubmit () {
      this.$emit('closeWindow');
    },
    onSubmit () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.startAndEndTime === undefined || this.form.startAndEndTime.length <= 0) {
            let params = {
              //   ...this.form
              recordNumber: this.form.recordNumber,
              recordState: this.form.recordState,
              projectId: this.form.projectId,
              projectName: this.form.projectName,
              customName: this.form.customName,
              ownerContact: this.form.ownerContact,
              ownerPhone: this.form.ownerPhone,
              contractAmount: this.form.contractAmount,
              contractGetDate: this.form.contractGetDate,
              tenderType: this.form.tenderType,
              projectManager: this.form.projectManager,
              projectArea: this.form.projectArea,
              tenderPrice: this.form.tenderPrice,
              fundSource: this.form.fundSource,
              tenderTime: this.form.tenderTime,
              tenderStartArea: this.form.tenderStartArea,
              tenderWinner: this.form.tenderWinner,
              recordTime: this.form.recordTime
            }
            // window.alert(decodeURI(JSON.stringify(params)));
            return new Promise((resolve, reject) => {
              InvitationStatisticsTable.updateTenderRecord0(this, decodeURI(JSON.stringify(params))).then(res => {
                this.$message({
                  showClose: true,
                  type: 'success',
                  message: '编辑成功!',
                  offset: '300',
                  onClose: () => {
                    this.$emit('updateWindow');
                  }
                });
              }).catch(e => {
                reject(e);
              });
            });
          } else {
            let startDate = this.form.startAndEndTime.toString();
            let params = {
              recordNumber: this.form.recordNumber,
              recordState: this.form.recordState,
              projectId: this.form.projectId,
              projectName: this.form.projectName,
              customName: this.form.customName,
              ownerContact: this.form.ownerContact,
              ownerPhone: this.form.ownerPhone,
              contractAmount: this.form.contractAmount,
              contractGetDate: this.form.contractGetDate,
              tenderType: this.form.tenderType,
              projectManager: this.form.projectManager,
              projectArea: this.form.projectArea,
              tenderPrice: this.form.tenderPrice,
              fundSource: this.form.fundSource,
              startTime: startDate.substring(0, 10),
              endTime: startDate.substring(11),
              tenderTime: this.form.tenderTime,
              tenderStartArea: this.form.tenderStartArea,
              tenderWinner: this.form.tenderWinner,
              recordTime: this.form.recordTime
            }
            //   window.alert(decodeURI(JSON.stringify(params)));
            return new Promise((resolve, reject) => {
              InvitationStatisticsTable.updateTenderRecord(this, decodeURI(JSON.stringify(params))).then(res => {
                this.$message({
                  showClose: true,
                  message: '编辑成功！',
                  type: 'success',
                  offset: '300',
                  onClose: () => {
                    this.$emit('updateWindow');
                  }
                });
              }).catch(e => {
                reject(e);
              });
            });
          }
        } else {
          this.$message({
            showClose: true,
            message: '编辑失败！',
            type: 'error',
            offset: '300'
          });
          return false;
        }
      });
    }
 
  }
}
</script>
<style>
    .mycontainer {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
    }
</style>
